import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders, HttpRequest } from '@angular/common/http';


@Injectable({
  providedIn: 'root'
})
export class RequestService {
  private http: any;
  headers: HttpHeaders = new HttpHeaders;
  withCredentials: boolean = false;
  fileName: string = '';
  defaultBody: any;
  constructor(http: HttpClient) {
    this.http = http;
  };


  upload(path: string, file: File) {
    var /** @type {?} */ req = new HttpRequest('POST', path, file, {
      headers: this.headers,
      reportProgress: true,
      withCredentials: this.withCredentials,
    });
    return this.http.request(req);
  }


  setHeader(headers: any) {
    if (headers === void 0) { headers = {}; }
    this.headers = new HttpHeaders(headers);
    return this;
  }

  setCredentials(withCredentials: boolean) {
    this.withCredentials = withCredentials;
    return this;
  }
  setFileName(name: string) {
    this.fileName = name;
    return this;
  }

  addExtraData(data: any) {
    if (data === void 0) { data = {}; }
    this.defaultBody = data;
    return this;
  }
}
